package com.wisdytech.linkdcs.measuretool.action;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.measuretool.model.MeasureTool;
import com.wisdytech.linkdcs.measuretool.service.IMeasureRecordService;
import com.wisdytech.linkdcs.measuretool.service.IMeasureToolService;
import com.wisdytech.linkdcs.measuretool.vo.MeasureToolCheckVO;
import com.wisdytech.linkdcs.system.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-15
 */
@Controller
@RequestMapping("/measureTool/measureToolCheck")
public class MeasureToolCheckAction {


    @Resource
    private IMeasureToolService measureToolService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    @Resource
    private IMeasureRecordService measureRecordService;

    /**
     *
     * <p>Description: 计量器具</p>
     * @param model model
     * @return String
     */
    @RequestMapping("/index")
    public String toolCheckIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "measuretool/measureToolCheck";
    }

    @RequestMapping(value = "/getMeasureToolCheckList/get.mvc")
    @ResponseBody
    public StandardTableResult<MeasureTool> getMeasureToolCheckList(String measureToolCode, String measureToolName, String checkType,  Filter filter) {
        PageInfo<MeasureTool> page = measureToolService.getMeasureToolCheckList(measureToolCode,
                measureToolName,
                null,
                checkType,
                null,
                null,
                null,
                null,
                filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }

    /**
     * @param vo 实体类
     * @return StandardResult
     */
    @RequestMapping(value = "/measureToolCheck/save.mvc")
    @ResponseBody
    public StandardResult measureToolCheck(@RequestBody MeasureToolCheckVO vo) {
        SysUser user = BaseUtil.getCurrentUser();
        this.measureRecordService.measureToolCheck(vo,user);
        return StandardResult.getSuccessResult();
    }

    /**
     * @param pkId 主键
     * @return StandardResult
     */
    @RequestMapping(value = "/getMeasureToolCheckBasicInfo/get.mvc")
    @ResponseBody
    public StandardResult getMeasureToolCheckBasicInfo(String pkId) {
        MeasureTool t = this.measureToolService.getMeasureToolCheckBasicInfo(pkId);
        return StandardResult.getSuccessResult(t);
    }


}
